package com.example.sls.service.impl.userDetails;

import com.example.sls.mapper.account.AccountMapper;
import com.example.sls.pojo.account.Account;
import com.example.sls.service.impl.userDetails.UserDetailsImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

//从数据库读取用户信息进行身份认证
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    AccountMapper accountMapper;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Account user = accountMapper.getAccountByUserName(username);
        if(user == null){
            throw new UsernameNotFoundException("用户不存在");
        }
        return new UserDetailsImpl(user);
    }
}
